import java.util.Scanner;
import java.util.Stack;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 强仔
 * Date: 2022-07-04
 * Time: 16:53
 */
public class Main {

    // Fibonacci数列
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();

        int first = 0;
        int second = 1;
        while(second < n){
            int third = first + second;
            first = second;
            second = third;
        }

        int result = Math.min(n - first, second - n);
        System.out.println(result);
    }

    // 合法括号序列判断
    public boolean chkParenthesis(String A, int n) {
        Stack<Character> stack = new Stack();
        char[] chars = A.toCharArray();
        for (int i = 0; i < n; i++) {
            if(stack.isEmpty()){
                stack.push(chars[i]);
            } else {
                char ch = stack.peek();
                if(ch == '(' && chars[i] == ')'){
                    stack.pop();
                }else {
                    stack.push(chars[i]);
                }
            }
        }

        return stack.isEmpty();
    }
}
